package com.xiaoge.transactionannotation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * TODO
 * 		1. 事务注解的方法是入口, 只要你调用的子方法报错或入口方法报错, 全部都会回滚
 * 		2. 事务注解的方法是入口, 你需要被调用的方法的事务注解也生效, 必须用代理对象调用
 *
 * @author <a href="mailto:1330137071@qq.com">Zhang Xiao</a>
 * @author <a href="mailto:zhangxiao@dist.com.cn">Zhang Xiao</a>
 * @since
 */
@Service
public class TestTransactionService {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Autowired
	private TestTransactionService testTransactionService;

	@Transactional
	public void test() {
		jdbcTemplate.execute("insert into t values (11)");
		test2();
		throw new NullPointerException();
	}

//	@Transactional(propagation = Propagation.NEVER)
	public void test2() {
		jdbcTemplate.execute("insert into t values (12)");
	}

}
